package com.good.test;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.codec.Hex;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/servlet-context.xml",
		"classpath*:/mvc-servlet.xml" })
@TransactionConfiguration(transactionManager = "txManager", defaultRollback = true)
public class Base64Demo {
	@Test
	public void test1() {
		String str="lusuce";
		String base64Encoded = Base64.encodeToString(str.getBytes());
		String str2 = Base64.decodeToString(base64Encoded); 
		System.out.println(base64Encoded+"===64code===="+str2);
		Assert.assertEquals(str, str2); 
	}
	@Test
	public void test2(){
		String str = "hello";
		String base64Encoded = Hex.encodeToString(str.getBytes());
		String str2 = new String(Hex.decode(base64Encoded.getBytes()));
		System.out.println(base64Encoded+"===="+str2);
		Assert.assertEquals(str, str2);
	}
	@Test
	public void test3(){
		String str = "hello";
		String salt = "123";
		String md5 = new Md5Hash(str, salt).toString();//还可以转换为 toBase64()/toHex()&nbsp;
		String md52=new Md5Hash("admin").toString();
		System.out.println(md5+"==="+md52);
	}
}
